package com.mallbook.model.service;

import com.mallbook.model.exception.ServiceException;
import com.mallbook.model.pojo.Region;
import com.mallbook.model.mapper.RegionMapper;
import com.mallbook.model.utils.MybatisUtils;
import org.apache.ibatis.exceptions.PersistenceException;

import java.util.List;

/**
 * @Author 宋明松
 * @Version V1.0.0
 * @Date 2022-06-25
 * 地址service层
 */
public class RegionService {


    /**
     * 按照pid查询
     *
     * @param id
     * @return
     */
    public Region getRegionByPid(Integer id) {
        RegionMapper regionMapper = MybatisUtils.getMappers(RegionMapper.class);
        try {
            return regionMapper.findRegionById(id);
        } catch (
                PersistenceException e) {
            throw new ServiceException("数据操作异常", e);
        }
    }

    /**
     * 按照pid查询
     *
     * @param pid
     * @return
     */
    public List<Region> getRegionByPidList(Integer pid) {
        RegionMapper regionMapper = MybatisUtils.getMappers(RegionMapper.class);
        try {
            return regionMapper.findRegionByPId(pid);
        } catch (
                PersistenceException e) {
            throw new ServiceException("数据操作异常", e);
        }
    }


}
